﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using PowerTestController.Models;
using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PowerTestController.ViewModes
{
    public partial class SerialPortViewModel : ObservableObject
    {
        public SerialPortViewModel()
        {
            SpModel = new SerialPortModel();
        }

        [ObservableProperty]
        private SerialPortModel spModel;

        [ObservableProperty]
        private SerialPort sp;

        [ObservableProperty]
        private bool result;

        [RelayCommand]
        private void Confirm()
        {
            Sp = new SerialPort(
                SpModel.PortName,
                SpModel.BaudRate,
                SpModel.Parity,
                SpModel.DataBits,
                SpModel.StopBits
            );
            Result = true;
            WeakReferenceMessenger.Default.Send<string,string>("","serialPort");
       
        }

        [RelayCommand]
        private void Cancel() {
            Result = false;
            WeakReferenceMessenger.Default.Send<string, string>("", "serialPort");

        }
    }
}
